package com.elite.controller;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.SessionAttribute;
import org.springframework.web.bind.annotation.SessionAttributes;

@RestController
@SessionAttributes("name")
public class TestSessionAttributesController {


	/**
	 * 测试
	 * @SessionAttributes注解，它会把Session的name属性赋值给Model参数
	 * @SessionAttribute注解，它会把Session的name赋值给当前方法参数
	 * @param
	 */
	@GetMapping("/testSessionAttribute")
	public void testSessionAttribute(@SessionAttribute("name") String name, Model model){

		System.out.println("name = " + name);
		Object sessionName = model.getAttribute("name");
		System.out.println("sessionName = " + sessionName);
	}


	@GetMapping("/setSession")
	public String setSession(String name, HttpServletRequest request){
		request.getSession().setAttribute("name","1111");
		return "Ok";
	}
}
